$(document).ready(function() {
	//if(navigator.appName!="Microsoft Internet Explorer") $("head").append('<link href="style.css" rel="stylesheet" type="text/css" />');
	//else $("head").append('<link href="style_ie.css" rel="stylesheet" type="text/css" />');
	$("#main li:first").css('background','none');
	var height_win = $(document).height();
	$("#bg_foo").height(height_win);
	
	$(".gender:first").css({"background":"url(images/radio_ac.jpg) no-repeat left"});
	$(".gender").click(function(){
		var id = ($(this).attr("id")).split("_");
		$("#gender").html(id[1]);
		$(".gender").css({"background":"url(images/radio.jpg) no-repeat left"});
		$(this).css({"background":"url(images/radio_ac.jpg) no-repeat left"});
	});
	
	$(".golfby:first").css({"background":"url(images/radio_ac.jpg) no-repeat left"});
	$(".golfby").click(function(){
		var id = ($(this).attr("id")).split("_");
		$("#golfby").html(id[1]);
		$(".golfby").css({"background":"url(images/radio.jpg) no-repeat left"});
		$(this).css({"background":"url(images/radio_ac.jpg) no-repeat left"});
	});
	
	$(".golffee:first").css({"background":"url(images/radio_ac.jpg) no-repeat left"});
	$(".golffee").click(function(){
		var id = ($(this).attr("id")).split("_");
		$("#golffee").html(id[1]);
		$(".golffee").css({"background":"url(images/radio.jpg) no-repeat left"});
		$(this).css({"background":"url(images/radio_ac.jpg) no-repeat left"});
	});
	
	$("#register").click(function(){
		var fullname = $("input[name=fullname]").val();
		var birth = $("input[name=birth]").val();
		var company = $("input[name=company]").val();
		var email = $("input[name=email]").val();
		var handicap = $("input[name=handicap]").val();
		var gender = $("#gender").html();
		var national = $("input[name=national]").val();
		var title = $("input[name=title]").val();
		var phone = $("input[name=phone]").val();
		var golfby = $("#golfby").html();
		var golffee = $("#golffee").html();
		if(fullname=='') $("input[name=fullname]").focus();
		else if(birth=='' || birth=='MM/DD/YYYY') $("input[name=birth]").focus().select();
		else if(company=='') $("input[name=company]").focus();
		else if(email=='') $("input[name=email]").focus();
		else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) $("input[name=email]").focus();
		else if(national=='') $("input[name=national]").focus();
		else if(title=='') $("input[name=title]").focus();
		else if(phone=='') $("input[name=phone]").focus();
		else if(gender=='' || golfby=='' || golffee=='') alert("Fail!");
		else{
			$(this).css('display','none');
			$("#loading").css('display','block');
			$.post("ajax.php",{register:'register',fullname:fullname,birth:birth,company:company,email:email,handicap:handicap,gender:gender,national:national,title:title,phone:phone,golfby:golfby,golffee:golffee},function(data){
				var host = window.location.host;
				if(data==1) setTimeout(function(){window.location = 'http://'+host+'/message-vietnam-works-golf-tournament/';},1000);
				else{ setTimeout(function(){alert("register failed!"); $("#register").css('display','block'); $("#loading").css('display','none');},1000) }
			});
		}
	});
});